import axios from "axios";
//<!-- 通道进出报表 -->
export default {
  data() {
    return {
      bigImgPath: '',
      detialType: '',
      exportSearchParams: {},
      modalData_searchParams: {},
      //异常放行
      modalData_abnormalOutCountTheads: [{
        propName: 'reno',
        label: "序号",
        width: 100
      }, {
        propName: 'reportDateStr',
        label: "日期",
        width: 150
      }, {
        propName: 'abnormalOutReason',
        label: "放行原因",
        width: 180
      }, {
        propName: 'carCount',
        label: "车辆数",
        width: 100
      }, {
        propName: 'totalLossTime',
        label: "累计停放时间（分钟）",
        width: 220
      }, {
        propName: 'lossTotal',
        label: "累计损失金额（元）",
        width: 220
      }],
      //非系统开闸
      modalData_abnormalOpenGateCountTheads: [{
        propName: 'reno',
        label: "序号",
        width: 110
      }, {
        propName: 'reportDateStr',
        label: "日期",
        width: 180
      }, {
        propName: 'openGateTypeStr',
        label: "开闸类型",
        width: 120
      }, {
        propName: 'carCount',
        label: "车辆数",
        width: 100
      }, {
        propName: 'totalLossTime',
        label: "累计停放时间（分钟）",
        width: 220
      }, {
        propName: 'lossTotal',
        label: "累计损失金额（元）",
        width: 220
      }],
      //红名单
      modalData_redlistVipParkingCountTheads: [{
        propName: 'reno',
        label: "序号",
        width: 64
      }, {
        propName: 'plateNum',
        label: "车牌号",
        width: 150
      }, {
        propName: 'cardNum',
        label: "卡号",
        width: 110
      }, {
        propName: 'parkingDuration',
        label: "停车时长",
        width: 110
      }, {
        propName: 'approchVipType',
        label: "进场VIP类型",
        width: 180
      }, {
        propName: 'leaveVipType',
        label: "离场VIP类型",
        width: 180
      }, {
        propName: 'parkName',
        label: "停车场",
        width: 180
      }, {
        propName: 'approchTime',
        label: "进场时间",
        width: 180
      }, {
        propName: 'leaveTime',
        label: "出场时间",
        width: 180
      }, {
        propName: 'approchChannel',
        label: "进场通道",
        width: 110
      }, {
        propName: 'leaveChannel',
        label: "出场通道",
        width: 110
      }, {
        propName: 'approchPlateUrl',
        label: "进场车牌图片",
        width: 140
      }, {
        propName: 'leavePlateUrl',
        label: "出场车牌图片",
        width: 140
      }, {
        propName: 'shouldValue',
        label: "应收",
        width: 110
      }, {
        propName: 'realValue',
        label: "实收",
        width: 110
      }, {
        propName: 'reliefValue',
        label: "优惠",
        width: 110
      }],
      //免费时间段内车辆
      modalData_freeTimeParkCountTheads: [{
        propName: 'reno',
        label: "序号",
        width: 68
      }, {
        propName: 'reportDateStr',
        label: "日期",
        width: 68
      }, {
        propName: 'openGateType',
        label: "开闸类型",
        width: 68
      }, {
        propName: 'carCount',
        label: "车辆数",
        width: 68
      }, {
        propName: 'totalLossTimeCount',
        label: "累计停放时间",
        width: 68
      }, {
        propName: 'lossTotal',
        label: "累计损失金额",
        width: 68
      }],
      modalData_abnormalOutCount: {
        tbBody: [],
        fixedCols: 2,
        rp: 10,
        page: 1,
        total: "",
      },
      modalData_abnormalOpenGateCount: {
        tbBody: [],
        fixedCols: 2,
        rp: 10,
        page: 1,
        total: "",
      },
      modalData_redlistVipParkingCount: {
        tbBody: [],
        fixedCols: 2,
        rp: 10,
        page: 1,
        total: "",
      },
      modalData_freeTimeParkCount: {
        tbBody: [],
        fixedCols: 2,
        rp: 10,
        page: 1,
        total: "",
      },
      parkNameListRow: {
        searchParams: {},
        pageNumber: 1,
        total: 0,
        theadsInfo: [{
            index: 0,
            isShow: false,
            prop: 'reno',
            text: '序号',
            width: 68
          },
          {
            index: 1,
            isShow: false,
            prop: 'm',
            text: '停车场',
            minWidth: 110
          }
        ],
        tbodysInfo: []
      },
      parkNameRow: {}
    }
  },
  created() {
    
  },
  methods: {
    // 重新生成按钮
    reBuild(){
      this.$refs.myReBuildBtn.reBuild()
    },
    showBigImgModal(name, path) {
      this.bigImgPath = path;
      this.toOpenImgModal(name, path);
    },
    getDefaultParams() { //获取不能缺少的默认的参数
      let self = this;
      let searchParams = self.searchParams,
        searchList = self.searchList,
        result = {};
      var itemreportDimension, itemdateFromTo;
      for (var key in searchList) {
        if (searchList.hasOwnProperty(key)) {
          var item = searchList[key];
          if (item.name == 'reportDimension') {
            itemreportDimension = item;
          } else if (item.name == 'dateFromTo') {
            itemdateFromTo = item;
          }
        }
      }
      if (!self.searchParams.reportDimension) {
        result.reportDimension = itemreportDimension.value;
      }
      if (!self.searchParams.reportDateFrom) {
        result.reportDateFrom = moment(itemdateFromTo.value[0]).format('YYYY-MM-DD HH:mm:ss');
        result.reportDateTo = moment(itemdateFromTo.value[1]).format('YYYY-MM-DD HH:mm:ss');
      }
      return result;
    },
    getList() {
      let params = $.extend({}, this.searchParams, this.otherParams, this.getDefaultParams());
      this.getParkChannelInoutReportList(params);
    },
    getParkChannelInoutReportList(aparams) { //查询列表
      let self = this,
        params = {
          page: this.pageNumber,
          rp: this.pageSize
        };
      params = $.extend({}, params, aparams);

      switch (params.reportDimension) {
        case 'day':
          //params['reportDateFrom'] = moment(params.reportDateFrom, 'YYYY-MM-DD').startOf('day').format('YYYY-MM-DD HH:mm:ss');
          //params['reportDateTo'] = moment(params.reportDateTo, 'YYYY-MM-DD').endOf('day').format('YYYY-MM-DD HH:mm:ss');
          break;
        case 'month':
          params['reportDateFrom'] = moment(params.reportDateFrom, 'YYYY-MM').startOf('month').format('YYYY-MM-DD HH:mm:ss');
          params['reportDateTo'] = moment(params.reportDateTo, 'YYYY-MM').startOf('month').format('YYYY-MM-DD 00:00:00');
          break;
        case 'year':
          params['reportDateFrom'] = moment(params.reportDateFrom, 'YYYY').startOf('year').format('YYYY-MM-DD HH:mm:ss');
          params['reportDateTo'] = moment(params.reportDateTo, 'YYYY').startOf('year').format('YYYY-MM-DD 00:00:00');
          break;
        case 'custom':
          params['reportDateFrom'] = params.reportDateFrom;
          params['reportDateTo'] = params.reportDateTo;
          break;
        default:
      }

      this.modalData_searchParams = params;
      API.report.GetNewParkChannelInoutReportData(params)
        .then(res => {
          let data = res.data,
            list = data.rows;
          self.tbodysInfo = list;
          self.total = data.total;
        }, err => {})
    },
    openDetial(type, row) {
      let obj = {};
      obj.parkId = row.parkId;
      obj.parkUuid = row.parkUuid;
      obj.channelType = row.channelType;
      obj.channelName = row.channelName;
      obj.reportDate = row.reportDate;
      obj.customCode = row.customCode;
      this.modalData_searchParams.rp = 10;
      this.modalData_searchParams.page = 1;
      switch (type) {
        //异常放行
        case 'abnormalOutCount':
          this._abnormalOutCount(obj);
          break;
          //非系统放行
        case 'abnormalOpenGateCount':
          this._abnormalOpenGateCount(obj);
          break;
          //红名单
        case 'redlistVipParkingCount':
          this.modalData_redlistVipParkingCount.total = Number(row.redlistVipParkingCount);
          this._redlistVipParkingCount(obj);
          break;
          //免费时间段内车辆
        case 'freeTimeParkCount':
          this._freeTimeParkCount(obj);
          break;
        default:
          break;
      }
    },
    initSearchParams(obj) {
      let _this = this;
      _this.modalData_searchParams.parkId = obj && obj.parkId ? obj.parkId : _this.modalData_searchParams.parkId;
      _this.modalData_searchParams.parkUuid = obj && obj.parkUuid ? obj.parkUuid : _this.modalData_searchParams.parkUuid;
      _this.modalData_searchParams.customCode = obj && obj.customCode ? obj.customCode : _this.modalData_searchParams.customCode;
      _this.modalData_searchParams.reportDate = obj && obj.reportDate ? obj.reportDate : _this.modalData_searchParams.reportDate;
      _this.modalData_searchParams.channelName = obj && obj.channelName ? obj.channelName : _this.modalData_searchParams.channelName;
      _this.modalData_searchParams.channelType = obj && obj.channelType ? obj.channelType : _this.modalData_searchParams.channelType;
      _this.modalData_searchParams.page = obj && obj.page ? obj.page : _this.modalData_searchParams.page;
      _this.modalData_searchParams.rp = obj && obj.rp ? obj.rp : _this.modalData_searchParams.rp;
    },
    calculateDate(type, timestamp) {
      switch (type) {
        case 'day':
          return moment(timestamp).format('YYYY-MM-DD HH:mm:ss') + " - " + moment(timestamp).add(1, 'days').add(-1, 'second').format('YYYY-MM-DD HH:mm:ss');
          break;
        case 'month':
          return moment(timestamp).format('YYYY-MM-DD HH:mm:ss') + " - " + moment(timestamp).add(1, 'month').add(-1, 'second').format('YYYY-MM-DD HH:mm:ss');
          break;
        case 'year':
          return moment(timestamp).format('YYYY-MM-DD HH:mm:ss') + " - " + moment(timestamp).add(1, 'year').add(-1, 'second').format('YYYY-MM-DD HH:mm:ss');
          break;
        default:
          break;
      }
    },
    handleSizeChange(val) {
      let obj = {};
      obj.rp = val;
      switch (this.detialType) {
        case "_abnormalOutCount":
          this._abnormalOutCount(obj);
          break;
        case "_abnormalOpenGateCount":
          this._abnormalOpenGateCount(obj);
          break;
        case "_redlistVipParkingCount":
          this._redlistVipParkingCount(obj);
          break;
        default:
          break;
      }

    },
    handleCurrentChange(val) {
      let obj = {};
      obj.page = val;
      switch (this.detialType) {
        case "_abnormalOutCount":
          this._abnormalOutCount(obj);
          break;
        case "_abnormalOpenGateCount":
          this._abnormalOpenGateCount(obj);
          break;
        case "_redlistVipParkingCount":
          this._redlistVipParkingCount(obj);
          break;
        case "_freeTimeParkCount":
          break;
        default:
          break;
      }
    },
    _abnormalOutCount(obj) {
      let _this = this;
      let queryParams = {};
      _this.initSearchParams(obj);
      queryParams['page'] = _this.modalData_searchParams.page;
      queryParams['rp'] = _this.modalData_searchParams.rp;
      queryParams['reportDimension'] = _this.modalData_searchParams.reportDimension;
      let x = [];
      x.push(_this.modalData_searchParams.parkId);
      queryParams['parkIds'] = x.join(',');
      queryParams['channelName'] = _this.modalData_searchParams.channelName;
      queryParams['channelType'] = _this.modalData_searchParams.channelType;
      queryParams['customCode'] = _this.modalData_searchParams.customCode;
      if (_this.modalData_searchParams['reportDimension'] != 'custom') {
        queryParams['reportDateFrom'] = _this.calculateDate(_this.modalData_searchParams['reportDimension'], _this.modalData_searchParams['reportDate']).split(' - ')[0];
        queryParams['reportDateTo'] = _this.calculateDate(_this.modalData_searchParams['reportDimension'], _this.modalData_searchParams['reportDate']).split(' - ')[1];
      } else {
        queryParams['reportDateFrom'] = _this.modalData_searchParams['reportDateFrom'];
        queryParams['reportDateTo'] = _this.modalData_searchParams['reportDateTo'];
      }

      _this.detialType = "_abnormalOutCount";
      _this.exportSearchParams = queryParams;
      axios.get("report/new_channel/abnormalOutReportPageList.do", {
        params: queryParams
      }).then(function (res) {
        _this.modalData_abnormalOutCount.tbBody = res.data.data.rows;
        _this.modalData_abnormalOutCount.total = Number(res.data.data.total);
        _this.modalData_abnormalOutCount.rp = Number(res.data.data.rp);
        _this.modalData_abnormalOutCount.page = Number(res.data.data.page);
        _this.toOpenModal("abnormalOutCountModal");
      }, ).catch(function (err) {

      })
    },
    _abnormalOpenGateCount(obj) {
      let _this = this;
      let queryParams = {};
      _this.initSearchParams(obj);
      queryParams['page'] = _this.modalData_searchParams.page;
      queryParams['rp'] = _this.modalData_searchParams.rp;
      queryParams['reportDimension'] = _this.modalData_searchParams.reportDimension;
      let x = [];
      x.push(_this.modalData_searchParams.parkId);
      queryParams['parkIds'] = x.join(',');
      queryParams['channelName'] = _this.modalData_searchParams.channelName;
      queryParams['channelType'] = _this.modalData_searchParams.channelType;
      queryParams['customCode'] = _this.modalData_searchParams.customCode;

      if (_this.modalData_searchParams['reportDimension'] != 'custom') {
        queryParams['reportDateFrom'] = _this.calculateDate(_this.modalData_searchParams['reportDimension'], _this.modalData_searchParams['reportDate']).split(' - ')[0];
        queryParams['reportDateTo'] = _this.calculateDate(_this.modalData_searchParams['reportDimension'], _this.modalData_searchParams['reportDate']).split(' - ')[1];
      } else {
        queryParams['reportDateFrom'] = _this.modalData_searchParams['reportDateFrom'];
        queryParams['reportDateTo'] = _this.modalData_searchParams['reportDateTo'];
      }

      _this.detialType = "_abnormalOpenGateCount";
      _this.exportSearchParams = queryParams;

      axios.get("report/new_channel/abnormalOpenGateOutReportPageList.do", {
        params: queryParams
      }).then(function (res) {
        _this.modalData_abnormalOpenGateCount.tbBody = res.data.data.rows;
        _this.modalData_abnormalOpenGateCount.total = Number(res.data.data.total);
        _this.modalData_abnormalOpenGateCount.rp = Number(res.data.data.rp);
        _this.modalData_abnormalOpenGateCount.page = Number(res.data.data.page);
        _this.toOpenModal("abnormalOpenGateCountModal");
      }, ).catch(function (err) {

      })

    },
    _redlistVipParkingCount(obj) {
      let _this = this;
      let queryParams = {};
      _this.initSearchParams(obj);
      queryParams.parkIds = _this.modalData_searchParams.parkId;
      queryParams.leaveChannel = _this.modalData_searchParams.channelName;
      queryParams.leaveVipTypeByte = 8;
      queryParams['customCode'] = _this.modalData_searchParams.customCode;
      queryParams['page'] = _this.modalData_searchParams.page;
      queryParams['rp'] = _this.modalData_searchParams.rp;
      if (_this.modalData_searchParams['reportDimension'] != 'custom') {
        queryParams['leaveTimeFrom'] = _this.calculateDate(_this.modalData_searchParams['reportDimension'], _this.modalData_searchParams['reportDate']).split(' - ')[0];
        queryParams['leaveTimeTo'] = _this.calculateDate(_this.modalData_searchParams['reportDimension'], _this.modalData_searchParams['reportDate']).split(' - ')[1];
      } else {
        queryParams['leaveTimeFrom'] = _this.modalData_searchParams['reportDateFrom'];
        queryParams['leaveTimeTo'] = _this.modalData_searchParams['reportDateTo'];
      }

      _this.detialType = "_redlistVipParkingCount";
      _this.exportSearchParams = queryParams;

      axios.get("/park/carLeaveHistory/getCarLeaveHistroyByPageNotToday.do", {
        params: queryParams
      }).then(function (res) {
        _this.modalData_redlistVipParkingCount.tbBody = res.data.data.rows;
        _this.modalData_redlistVipParkingCount.rp = Number(res.data.data.rp);
        _this.modalData_redlistVipParkingCount.page = Number(res.data.data.page);
        _this.toOpenModal("redlistVipParkingCountModal");
      }, ).catch(function (err) {

      })
    },
    _freeTimeParkCount(obj) {
      let _this = this;
      let queryParams = {};
      _this.initSearchParams(obj);
      queryParams = $.extend({}, _this.modalData_searchParams);

      _this.detialType = "_freeTimeParkCount";
      axios.get("/park/carLeaveHistory/getCarLeaveHistroyByPage.do", {
        params: queryParams
      }).then(function (res) {
        _this.modalData_freeTimeParkCount.tbBody = res.data.data.rows;
        _this.modalData_freeTimeParkCount.total = Number(res.data.data.total);
        _this.modalData_freeTimeParkCount.rp = Number(res.data.data.rp);
        _this.modalData_freeTimeParkCount.page = Number(res.data.data.page);
        _this.toOpenModal("freeTimeParkCountModal");
      }, ).catch(function (err) {

      })
    },
    //导出
    exportData() {
      let self = this;
      self.showDialog("是否确认导出记录？", [], function () {
        let params = {};
        params = $.extend({}, params, self.searchParams, self.otherParams, self.getDefaultParams());

        switch (params.reportDimension) {
          case 'day':
            //params['reportDateFrom'] = moment(params.reportDateFrom, 'YYYY-MM-DD').startOf('day').format('YYYY-MM-DD HH:mm:ss');
            //params['reportDateTo'] = moment(params.reportDateTo, 'YYYY-MM-DD').endOf('day').format('YYYY-MM-DD HH:mm:ss');
            break;
          case 'month':
            params['reportDateFrom'] = moment(params.reportDateFrom, 'YYYY-MM').startOf('month').format('YYYY-MM-DD HH:mm:ss');
            params['reportDateTo'] = moment(params.reportDateTo, 'YYYY-MM').startOf('month').format('YYYY-MM-DD 00:00:00');
            break;
          case 'year':
            params['reportDateFrom'] = moment(params.reportDateFrom, 'YYYY').startOf('year').format('YYYY-MM-DD HH:mm:ss');
            params['reportDateTo'] = moment(params.reportDateTo, 'YYYY').startOf('year').format('YYYY-MM-DD 00:00:00');
            break;
          case 'custom':
            params['reportDateFrom'] = params.reportDateFrom;
            params['reportDateTo'] = params.reportDateTo;
            break;
          default:
        }
        self.toExportAsync('/report/new_channel/export.do', params);
      }, "温馨提示", function () {
        //取消时不操作
      });
    },
    //弹框导出
    modalexportFn(urlName) {
      let _this = this;
      let exportParams = $.extend({}, _this.exportSearchParams);
      exportParams.page = 1;
      exportParams.rp = 2000;
      _this.toExport(urlName, exportParams);
    },
    //必须定义获取多列的方法
    filterMultiCheck(selectionArr) {
      let result = [];
      selectionArr.map((item) => {
        result.push(item.id);
      });
      return result;
    },
  }
}
